using System;
using System.Windows.Threading;

namespace VSTalk.Tools
{
    /// <summary>
    /// Wraps the action delegate into an object. The delegate will be executed in the dispatcher
    /// thread.
    /// <example>
    /// Push agsXMPP event into a UI thread. 
    /// </example>
    /// </summary>
    public static class DispatcherHelper
    {
        public static IActionWrapper<T> Wrap<T>(this Dispatcher dispatcher, Action<T> action)
        {
            return new ActionWrapper<T>(o => dispatcher.Invoke(new Action(() => action(o))));
        }

        public static IActionWrapper<T1, T2> Wrap<T1, T2>(this Dispatcher dispatcher, Action<T1, T2> action)
        {
            return new ActionWrapper<T1, T2>((o1, o2)=> dispatcher.Invoke(new Action(() => action(o1, o2))));
        }

        public static IActionWrapper<T1, T2, T3> Wrap<T1, T2, T3>(this Dispatcher dispatcher, Action<T1, T2, T3> action)
        {
            return new ActionWrapper<T1, T2, T3>((o1, o2, o3) => dispatcher.Invoke(new Action(() => action(o1, o2, o3))));
        }
    }
}